#include "browser_view_delegate.h"

int CEF_CALLBACK on_popup_browser_view_created(struct _cef_browser_view_delegate_t *self,
                                               struct _cef_browser_view_t *browser_view,
                                               struct _cef_browser_view_t *popup_browser_view, int is_devtools) {
    LOG_DEBUG("start");
    browser_view_delegate *view_delegate = (browser_view_delegate *)self;
    window_delegate *window_delegate = _create_window_delegate(popup_browser_view, view_delegate->popup_width, view_delegate->popup_height, view_delegate->popup_icon_png_path, view_delegate->popup_title, view_delegate->is_popup_frameless, is_devtools);

    cef_window_t *window = cef_window_create_top_level(&(window_delegate->cef_window_delegate));
    
    LOG_DEBUG("end");
    return 1;
}

// 初始化 browser_view_delegate_ref_t
browser_view_delegate *create_browser_view_delegate_t(int popup_width, int popup_height, char *popup_icon_png_path, char *popup_title,int is_popup_frameless) {
    browser_view_delegate *view_delegate = (browser_view_delegate *)calloc(1, sizeof(browser_view_delegate));
    view_delegate->cef_browser_view_delegate.base.base.size = sizeof(cef_browser_view_delegate_t);

    view_delegate->cef_browser_view_delegate.on_popup_browser_view_created = on_popup_browser_view_created;
    view_delegate->popup_height = popup_height;
    view_delegate->popup_width = popup_width;
    view_delegate->popup_icon_png_path = strdup(popup_icon_png_path);
    view_delegate->popup_title = strdup(popup_title);
    view_delegate->is_popup_frameless = is_popup_frameless;
    // printf("create_browser_view_delegate_ref 2222...................\n");
    return view_delegate;
}
